package org.icosagon.utils;

import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import org.icosagon.core.math.Equation;
import org.icosagon.core.InvalidNumberException;

/**
 * This object is used to store units of time. May it be hours,
 * minutes or rounds.
 * @author Daniel Owens
 */
@XmlRootElement
public class Time {
    public static final String DAY = "DAY";
    public static final String HOUR ="HOUR";
    public static final String MINUTE ="MINUTE";
    public static final String ROUND = "ROUND";
    public static final String STANDARD = "STANDARD ACTION";
    public static final String FREE = "FREE ACTION";

    @XmlElement(name="unit")
    private String unit = "ROUND";
    @XmlElement(name="value")
    //private Equation time = new Equation();
    private String time = "";

    public Time() {}
    public Time(String unit) {
        this.unit = unit;
    }

    public void setValue(int value) {
        if(value >= 0)
            this.time = String.valueOf(value);
        else {
            InvalidNumberException ex = new InvalidNumberException("Time can not be less than zero.");
            ex.setInvalidNumber(value);
            throw ex;
        }
    }

    public void setValue(Equation equation) {
        if(equation == null)
            this.time = "0";
        this.time = equation.getEquation();
    }

    public Equation getValue() {
        return new Equation(this.time);
    }

    public void setUnit(String value) {
	this.unit = value;
    }

    public String getUnit() {
        return this.unit;
    }
}